package com.example.demo.customer;

import com.example.demo.exception.NotFoundException;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;


@Service
public class CustomerService {

private final static Logger LOGGER = LoggerFactory.getLogger(CustomerService.class);

    private  final CustomerRespository customerRespository;

    @Autowired

    public CustomerService(CustomerRespository customerRespository)
    {
        this.customerRespository=customerRespository;
    }
    List<Customer> getCustomers(){
LOGGER.info("getCustomers called");
        return  customerRespository.findAll();
}

Customer getCustomer(Long id) {
    return customerRespository
           .findById(id)
            .orElseThrow(() ->{
       NotFoundException notFoundException=  new NotFoundException("customer" +id+" 无法找到");
    LOGGER.error("error: getCustomer {}" + id, notFoundException);
    return notFoundException;
});
}
}
